import { _decorator, Component, Node, EditBox, Button, Label } from "cc";
import { CommonUtil } from "db://assets/Scripts/Utils/CommonUtil";
import { CheckOutEnum } from "db://assets/Scripts/Utils/CheckOutEnum";
const { ccclass, property } = _decorator;

@ccclass("RegPageManager")
export class RegPageManager extends Component {
  checkOutEnum: CheckOutEnum;
  commonUtil: CommonUtil;
  enumData: any;
  nodeName: string = "RegisterPage";

  @property
  localRegisterNode: Node = null;

  constructor() {
    super();
    this.commonUtil = CommonUtil.getInstance();
    this.checkOutEnum = CheckOutEnum.getInstance();
    this.enumData = this.checkOutEnum.getEnumByType();
  }

  configureRegisterPage(): void {
    const mainSplash = this.localRegisterNode.getChildByName("MainSplash");
    this.configureEditBox(mainSplash);
    this.configureButton(mainSplash, "CancelBtn", this.enumData.CANCEL);
    this.configureButton(mainSplash, "SaveBtn", this.enumData.CONFIRM);
  }

  configureEditBox(nodeParam: Node): void {
    const editBoxNode = nodeParam.getChildByName("EditBoxTag");
    const editBoxComponent = editBoxNode.getComponent(EditBox);
    editBoxComponent.placeholder = this.enumData.PLS_ENTER_NICK_NAME;
  }

  configureButton(
    nodeParam: Node,
    buttonName: string,
    buttonText: string
  ): void {
    const buttonNode = nodeParam.getChildByName(buttonName);
    const labelNode = buttonNode.getChildByName("Label");
    const labelComponent = labelNode.getComponent(Label);
    labelComponent.string = buttonText;
  }

  initialization() {
    this.localRegisterNode = this.node.getChildByName(this.nodeName);
    this.configureRegisterPage();
  }
}
